/**
 * 345. 反转字符串中的元音字母
 * 已知字符串 s, 仅反转字符串中的所有元音字母，并返回字符串
 * 元音字母包括 a, e, i, o, u，且可能以大小写两种形式出现
 * @link https://leetcode-cn.com/problems/reverse-vowels-of-a-string/description/
 *
 * @param {string} s
 * @return {string}
 */
var reverseVowels = function (s) {
    let start = 0;
    let end = s.length - 1;
    const array = new Array(s.length);

    while (start <= end) {
        const c1 = s.charAt(start);
        const c2 = s.charAt(end);
        if (!isVowel(c1)) {
            array[start++] = c1;
        } else if (!isVowel(c2)) {
            array[end--] = c2;
        } else {
            array[start++] = c2;
            array[end--] = c1;
        }
    }

    return array.join('');
};

/**
 *
 * @param {string} c
 * @return {boolean}
 */
function isVowel(c) {
    return 'aeiouAEIOU'.includes(c);
}
